import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.UnknownHostException;

import socketHttpGet.*;



public class Main
{
	
	public static void commandLineInterface (String message) throws UnknownHostException, IOException
	{
		SocketGet sg = new SocketGet ();
		BufferedReader cin = new BufferedReader(new InputStreamReader(System.in));
		String exit = "exit";
		String input = "";
		System.out.println(message);
		double quoteVal = 0;
		
		while(true)
		{
			System.out.print(">");
			try
			{
				input = new String();
				input = cin.readLine();
				
				if(input.equals(exit))
					break;
				
				quoteVal = sg.getQuote(input);
				
				System.out.println(quoteVal);
				
			} 
			catch (IOException e)
			{
				e.printStackTrace();
			}
		}
	}

	/**
	 * @param args
	 */
	public static void main(String[] args)
	{
		if(args.length == 0)
		{
			try
			{
				Main.commandLineInterface("Please enter a ticker symbol or 'exit' to quit:");
				System.out.println("bye!");
			} 
			catch (MalformedURLException e)
			{
				e.printStackTrace();
			} catch (UnknownHostException e)
			{
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e)
			{
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		else
		{
			try
			{
				SocketGet sg = new SocketGet ();
				double quoteVal = sg.getQuote(args[0]);
				System.out.println(quoteVal);
			} catch (UnknownHostException e)
			{
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e)
			{
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		}
	}

}
